<?php
    require_once ("Includes/session.php");
    require_once ("Includes/simplecms-config.php"); 
    require_once ("Includes/connectDB.php");
    require_once("conf.php");   
    include("Includes/header.php");

     confirm_is_admin();
?>
<div id="fullmain">
<?php
    $val = trim($_SERVER['QUERY_STRING']);
    if(!empty($val))
    {
        $temp =explode('=', $val);
        $type = $temp[0];

        if($type == 'id')
        {
            $student_id =  $temp[1];
            $dg = new C_DataGrid("SELECT exam_attempts.id AS at_id , user_id , exam_id , ready , anstime , mark , title   FROM exam_attempts INNER JOIN exams on exam_attempts.exam_id = exams.id", "at_id", "Attempts");
            $dg -> set_query_filter("user_id = ".$student_id);
            $dg -> set_dimension(400, 300); 
            $dg -> set_col_hidden("at_id");
            $dg -> set_col_hidden("user_id");
            $dg -> set_col_hidden("exam_id");
            
            $dg -> set_col_hidden("ready");
            $dg -> set_col_title("title", "Exam");
            $dg -> set_col_title("anstime", "Date");
            
            $dg -> set_col_title("mark", "Score");
            $dg -> enable_export('PDF');
            $dg -> enable_export('EXCEL');
            $dg -> enable_search(true);
            $dg -> enable_advanced_search(true);
            $onSelectRow = <<<ONSELECTROW
            function(status, rowid)
            {
                window.location = "Admin_Reports.php?exam=" + rowid;
	            //alert(rowid);
            }
ONSELECTROW;


            $dg -> add_event("jqGridDblClickRow", $onSelectRow);
            $dg -> display();

        }
        elseif($type == 'exam')
        {
            $attempt_id =  $temp[1];
            $dg = new C_DataGrid("SELECT * FROM answers 
            INNER JOIN exam_attempts on exam_attempts.id = answers.exam_attempt_id 
            INNER JOIN questions on answers.question_id = questions.id", "id", "Attempts");
            //$dg -> set_query_filter("user_id = ".$_SESSION['userid']);
            $dg -> set_query_filter("exam_attempt_id = ".$attempt_id);
            $dg -> set_dimension(600, 500); 
            $dg -> set_col_hidden("id");
            $dg -> set_col_hidden("user_id");
            $dg -> set_col_hidden("exam_id");
            $dg -> set_col_hidden("C1");
            $dg -> set_col_hidden("C2");
            $dg -> set_col_hidden("C3");
            $dg -> set_col_hidden("C4");
            $dg -> set_col_hidden("mark");
            $dg -> set_col_hidden("question_id");
            $dg -> set_col_hidden("exam_attempt_id");
            $dg -> set_col_title("AIndex", "Correct Answer");
            $dg -> set_col_title("title", "Exam");
            $dg -> set_col_title("anstime", "Date");
            $dg -> enable_export('PDF');
            $dg -> enable_export('EXCEL');
            $dg -> enable_search(true);
            $dg -> enable_advanced_search(true);



            //$dg->add_event("jqGridSelectRow", $onSelectRow);
            //$dg -> add_event("jqGridDblClickRow", $onSelectRow);
            $dg -> display();

          
        }

    }
    else
    {

        $dg = new C_DataGrid("SELECT users.id,users.username FROM users INNER JOIN users_in_roles ON users.id = users_in_roles.user_id", "id", "Users");
        $dg -> set_query_filter("users_in_roles.role_id = 2");
        $dg -> set_dimension(400, 300); 
        $dg -> set_col_hidden("id");
        $onSelectRow = <<<ONSELECTROW
        function(status, rowid)
        {
            window.location = "Admin_Reports.php?id=" + rowid;
        }
ONSELECTROW;


        //$dg->add_event("jqGridSelectRow", $onSelectRow);
        $dg -> add_event("jqGridDblClickRow", $onSelectRow);
        $dg -> display();
    }
?>
    </div>
</div>

<?php include ("Includes/footer.php"); ?>